home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / dialip10.zip / CHKPOP.CMD next >
OS/2 REXX Batch file  |  1996-11-18  |  7KB  |  255 lines

  1. /*------------------------------------------------------------------
  2.  * chkpop.cmd :
  3.  *------------------------------------------------------------------
  4.  * 08-09-92 rnr.cmd published originally by Patrick J. Mueller
  5.  * 24-01-95 adapted as chkpop.cmd by Christoph Lechleitner
  6.  * 15-12-96 fixed for more RFC-compatibility by C. Lechleitner
  7.  * Nov-96 Added code to notify user of new mail.  Stan J. Towianski
  8.  *------------------------------------------------------------------*/
  9.  
  10. trace off
  11.  
  12. parse arg server user password
  13.  
  14. if (server = "") | (user='') | (password='') then
  15.    do
  16.    say " Error: Expecting a pop server name, a user and a password as parameters."
  17.    exit 0
  18.    end
  19. say ' '
  20.  
  21. /*------------------------------------------------------------------
  22.  * initialize socket function package
  23.  *------------------------------------------------------------------*/
  24. parse source os .
  25.  
  26. if (os = "OS/2") then
  27.    do
  28.    if RxFuncQuery("SockLoadFuncs") then
  29.       do
  30.       rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  31.       rc = SockLoadFuncs()
  32.       end
  33.    end
  34.  
  35. if (os = "AIX/6000") then
  36.    do
  37.    rc = SysAddFuncPkg("rxsock.dll")
  38.    end
  39.  
  40. /*------------------------------------------------------------------
  41.  * get address of server
  42.  *------------------------------------------------------------------*/
  43. rc = SockGetHostByName(server,"host.!")
  44. if (rc = 0) then
  45.    do
  46.    say "Error: Unable to resolve server name" server
  47.    exit 0
  48.    end
  49.  
  50. server = host.!addr
  51.  
  52. /*------------------------------------------------------------------
  53.  * open socket
  54.  *------------------------------------------------------------------*/
  55. sock = SockSocket("AF_INET","SOCK_STREAM","IPPROTO_TCP")
  56. if (sock = -1) then
  57.    do
  58.    say "Error opening socket:" errno
  59.    exit 0
  60.    end
  61.  
  62. /*------------------------------------------------------------------
  63.  * connect socket
  64.  *------------------------------------------------------------------*/
  65. server.!family = "AF_INET"
  66. server.!port   = 110
  67. server.!addr   = server
  68.  
  69. rc = SockConnect(sock,"server.!")
  70. if (rc = -1) then
  71.    Error(sock,rc,"Error connecting to popserver :" errno)
  72.  
  73.    trc = GetResponse(sock)
  74.  
  75.    trc = SendMessage(sock,'USER 'user)
  76.    trc = GetResponse(sock)
  77.    parse var line.1 status rest
  78.    if status <> '+OK' then
  79.      do
  80.        say ' Error: User' user 'unknown on' server '.'
  81.        qrc = SendMessage(sock,'QUIT')
  82.        qrc = SockSoclose(sock)
  83.        Error(sock,1,"" sigl)
  84.      end
  85.  
  86.    trc = SendMessage(sock,'PASS 'password)
  87.    trc = GetResponse(sock)
  88.    parse var line.1 status rest
  89.    if status <> '+OK' then
  90.      do
  91.        say ' Error: Password wrong for' user ' on 'server'.'
  92.        qrc = SendMessage(sock,'QUIT')
  93.        qrc = SockSoclose(sock)
  94.        Error(sock,1,"" sigl)
  95.      end
  96.    else
  97.      do 
  98.        trc = SendMessage(sock,'LIST')
  99.        trc = GetResponse(sock)
  100.        messages = 0
  101.        do 
  102.          msginfo = GetResponseLine(sock)
  103.          do while msginfo <> '.'
  104.            messages = messages + 1
  105.            msginfo = GetResponseLine(sock)
  106.          end
  107.          if messages = 0 
  108.          then say ' There is no message waiting for you.'
  109.          else
  110.            do 
  111.              say ' There are' messages 'messages waiting for you.'
  112.              'start /min notify' messages
  113.              trc = SendMessage(sock,'LIST')
  114.              trc = GetResponse(sock)
  115.              do 
  116.                msginfo = GetResponseLine(sock)
  117.                do while msginfo <> '.'
  118.                  parse var msginfo number size
  119.                  say ' Message' number 'has' size 'bytes.'
  120.                  msginfo = GetResponseLine(sock)
  121.                end
  122.              end /* do */
  123.        end
  124.      end /* do */
  125.  
  126.    trc = SendMessage(sock,'QUIT')
  127.    trc = GetResponse(sock)
  128.  
  129. /*------------------------------------------------------------------
  130.  * quittin' time!
  131.  *------------------------------------------------------------------*/
  132. /* rc = SendMessage(sock,"quit") */
  133. rc = SockSoclose(sock)
  134. exit messages
  135.  
  136.  
  137. /*------------------------------------------------------------------
  138.  * help
  139.  *------------------------------------------------------------------*/
  140. Help: procedure
  141.    say "commands:"
  142.    say
  143.    say "quit    - to quit"
  144.    say "group   - to change to a particular group"
  145.    say "article - to see an article"
  146.    say
  147.    return ""
  148.  
  149. /*------------------------------------------------------------------
  150.  * get a response from the server
  151.  *------------------------------------------------------------------*/
  152. GetResponse:     procedure expose !. line.
  153.    sock = arg(1)
  154.  
  155.    moreids = "100 215 220 221 222 223 230 231"
  156.  
  157.    line.0 = 1
  158.    line.1 = GetResponseLine(sock)
  159.  
  160.    parse var line.1 rid .
  161.  
  162.    if (wordpos(rid,moreids) = 0) then
  163.       return ""
  164.  
  165.    say ' getting further lines '
  166.  
  167.    do forever
  168.       o = line.0 + 1
  169.  
  170.       line.o = GetResponseLine(sock)
  171.  
  172.       if (line.o = ".") then
  173.          return ""
  174.  
  175.       line.0 = o
  176.    end
  177.  
  178.    return ""
  179.  
  180. /*------------------------------------------------------------------
  181.  * get a line from the server
  182.  *------------------------------------------------------------------*/
  183. GetResponseLine: procedure expose !.
  184.    sock = arg(1)
  185.  
  186.    crlf = d2c(13) || d2c(10)
  187.  
  188.    if (symbol('!.buff') = "LIT") then
  189.       !.buff = ""
  190.  
  191.    do while (pos(crlf,!.buff) = 0)
  192.       rc = SockRecv(sock,"data",8000)
  193.       !.buff = !.buff || data
  194.    end
  195.  
  196.    /* say ' got data "' data '"' */
  197.    /* say ' buff = "' !.buff '"' */
  198.  
  199.  
  200.    p = pos(crlf,!.buff)
  201.  
  202.    line = substr(!.buff,1,p-1)
  203.    !.buff = substr(!.buff,p+2)
  204.  
  205.    return line
  206.  
  207. /*------------------------------------------------------------------
  208.  * send a string to the server
  209.  *------------------------------------------------------------------*/
  210. SendMessage:     procedure expose !.
  211.    sock = arg(1)
  212.    data = arg(2) || d2c(13) || d2c(10)
  213.  
  214.    /* say 'Sending "'data'" to server.' */
  215.    len = length(data)
  216.    do while (len > 0)
  217.  
  218.       len = SockSend(sock,data);
  219.       /* say 'Returncode: ' len   */
  220.       /* say 'Errorcode:  ' errno */
  221.       /*
  222.       if (errno <> 0) then
  223.          Error(-1,rc,"Error sending data to server.")
  224.       */
  225.       if (len <= 0) then
  226.          Error(sock,100,"Server closed the connection.")
  227.       
  228.       data = substr(data,len+1)
  229.       len  = length(data)
  230.    end
  231.  
  232.    return i
  233.  
  234. /*------------------------------------------------------------------
  235.  * halting ...
  236.  *------------------------------------------------------------------*/
  237. Halting:
  238.    Error(sock,1,"error on line" sigl)
  239.  
  240. /*------------------------------------------------------------------
  241.  * exit with a message and return code
  242.  *------------------------------------------------------------------*/
  243. Error: procedure
  244.    sock = arg(1)
  245.    retc = arg(2)
  246.    msg  = arg(3)
  247.  
  248.    if (sock <> -1) then
  249.       rc = SockSoClose(sock)
  250.  
  251.    say msg
  252.  
  253.    exit retc
  254.  
  255.